package com.erlinyou.im.web.handle;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.erlinyou.im.web.controller.base.RequestUtil;
import com.erlinyou.im.web.controller.base.ResultCode;
import com.erlinyou.im.web.controller.base.ResultJson;
import com.erlinyou.im.web.controller.base.ResultJsonBuild;


@ControllerAdvice
public class ExceptionHandle {

    private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultJson<Object> handle(Exception e,HttpServletRequest request) {
    	ResultJson<Object> json = ResultJsonBuild.buildObj(ResultCode.UNKONW_ERROR);
    	logger.error("ip:"+RequestUtil.getRemoteHost(request)+",uri:"+request.getRequestURI()+",params:"+RequestUtil.getRequestMap(request)+",系统异常:",e);
    	return json;
    }
}
